package com.ruoyi.airsystem.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.airsystem.domain.AirFormaldehyde;
import com.ruoyi.airsystem.service.IAirFormaldehydeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 甲醛浓度记录Controller
 * @date 2025-04-18
 */
@RestController
@RequestMapping("/airsystem/formaldehyde")
public class AirFormaldehydeController extends BaseController
{
    @Autowired
    private IAirFormaldehydeService airFormaldehydeService;

    /**
     * 查询甲醛浓度记录列表
     */
    @PreAuthorize("@ss.hasPermi('airsystem:formaldehyde:list')")
    @GetMapping("/list")
    public TableDataInfo list(AirFormaldehyde airFormaldehyde)
    {
        startPage();
        List<AirFormaldehyde> list = airFormaldehydeService.selectAirFormaldehydeList(airFormaldehyde);
        return getDataTable(list);
    }

    /**
     * 导出甲醛浓度记录列表
     */
    @PreAuthorize("@ss.hasPermi('airsystem:formaldehyde:export')")
    @Log(title = "甲醛浓度记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AirFormaldehyde airFormaldehyde)
    {
        List<AirFormaldehyde> list = airFormaldehydeService.selectAirFormaldehydeList(airFormaldehyde);
        ExcelUtil<AirFormaldehyde> util = new ExcelUtil<AirFormaldehyde>(AirFormaldehyde.class);
        util.exportExcel(response, list, "甲醛浓度记录数据");
    }

    /**
     * 获取甲醛浓度记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('airsystem:formaldehyde:query')")
    @GetMapping(value = "/{recordId}")
    public AjaxResult getInfo(@PathVariable("recordId") Long recordId)
    {
        return success(airFormaldehydeService.selectAirFormaldehydeByRecordId(recordId));
    }

    /**
     * 新增甲醛浓度记录
     */
@PreAuthorize("@ss.hasPermi('airsystem:formaldehyde:add')")
@Log(title = "甲醛浓度记录", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody AirFormaldehyde airFormaldehyde)
{
    // 通过实例对象调用非静态方法
    airFormaldehydeService.checkAndInsertWarning(airFormaldehyde);
    return toAjax(airFormaldehydeService.insertAirFormaldehyde(airFormaldehyde));
}


    /**
     * 修改甲醛浓度记录
     */
    @PreAuthorize("@ss.hasPermi('airsystem:formaldehyde:edit')")
    @Log(title = "甲醛浓度记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AirFormaldehyde airFormaldehyde)
    {
        return toAjax(airFormaldehydeService.updateAirFormaldehyde(airFormaldehyde));
    }

    /**
     * 删除甲醛浓度记录
     */
    @PreAuthorize("@ss.hasPermi('airsystem:formaldehyde:remove')")
    @Log(title = "甲醛浓度记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recordIds}")
    public AjaxResult remove(@PathVariable Long[] recordIds)
    {
        return toAjax(airFormaldehydeService.deleteAirFormaldehydeByRecordIds(recordIds));
    }
}
